﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MTEA.ComStruct
{
    public class CircularBuffer<T> 
    {
        private T[] buffer;
        private int nextFree;

        public CircularBuffer(int length)
        {
            buffer = new T[length];
            nextFree = 0;
        }

        public void Add(T o)
        {
            buffer[nextFree] = o;
            nextFree = (nextFree + 1) % buffer.Length;
        }

        public T[] CopyArray()
        {
            return buffer.ToArray();
        }
    }
}
